package com.fhz.a1909.day002.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.fhz.a1909.R;

public class RightFragment extends Fragment {



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_right, container, false);

        FragmentViewModel fragmentViewModel = new ViewModelProvider(getActivity()).get(FragmentViewModel.class);
        TextView viewById = inflate.findViewById(R.id.right_text);

        fragmentViewModel.getSelected().observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                viewById.setText(s);
            }
        });
        return inflate;
    }
}